package com.lzh.others.collection.Map;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.lzh.others.collection.Map.entity.*;

import java.util.HashMap;
import java.util.List;

/**
 * Map反序列化
 */
public class MapTest {
    public static void main(String[] args) throws JsonProcessingException {
//        String jsonStr = "[\n    \n    {\n        \"XXLX\": \"04\",\n        \"SJDY\": {\n            \"DJZS\": 2500,\n            \"DJFHBFB\": 80,\n            \"DCDY\": 4800,\n            \"DCDL\": 120,\n            \"DCDLBFB\": 90\n        }\n    },\n    {\n        \"XXLX\": \"03\",\n        \"SJDY\": {\n            \"CS\": 120.5,\n            \"DQYL\": 100.2,\n            \"FDJNJ\": 10.5,\n            \"MCNJ\": 5.2,\n            \"FDJZS\": 2500,\n            \"FDJRLLL\": 1560,\n            \"TWCSY\": 0.8,\n            \"TWCXY\": 1.2,\n            \"JQL\": 1000,\n            \"FDJLQYWD\": 90,\n            \"TWCWD\": 300,\n            \"DWZT\": 1,\n            \"JD\": 113.55,\n            \"WD\": 22.65,\n            \"LJLC\": 250000\n        }\n    },\n    {\n        \"XXLX\": \"05\",\n        \"SJDY\": {\n            \"CS\": 120.5,\n            \"DQYL\": 100.2,\n            \"FDJNJ\": 10.5,\n            \"MCNJ\": 5.2,\n            \"FDJZS\": 2500,\n            \"FDJRLLL\": 1560,\n            \"TWCSY\": 0.8,\n            \"TWCXY\": 1.2,\n            \"TWCNOX\": 100,\n            \"JQL\": 1000,\n            \"FDJLQYWD\": 90,\n            \"TWCWD\": 300,\n            \"DWZT\": 1,\n            \"JD\": 113.55,\n            \"WD\": 22.65,\n            \"LJLC\": 250000\n        }\n    },\n    {\n        \"XXLX\": \"80\",\n        \"SJDY\": {\n            \"FDJNJMS\": \"9\",\n            \"YMTB\": 50,\n            \"LJYH\": 150000,\n            \"NSXWD\": 80,\n            \"SJNSPSL\": 2000,\n            \"LJNSXH\": 5550,\n            \"DPFWD\": 500\n        }\n    },\n    {\n        \"XXLX\": \"01\",\n        \"SJDY\": {\n            \"OBDZDXY\": \"0\",\n            \"MIL\": \"0\",\n            \"ZDZCZT\": \"0000000000000000\",\n            \"ZDJXZT\": \"0000000000000000\",\n            \"VIN\": \"12345678901234567\",\n            \"RJBDSBH\": \"222222222222222222\",\n            \"CVN\": \"222222222222222222\",\n            \"IUPR\": \"012345678901234567890123456\",\n            \"GZMZS\": 2,\n            \"GZMLB\": \"41104120\"\n        }\n    }\n]";
//        String jsonStr1 = "[\n" +
//                "    \n" +
//                "    {\n" +
//                "        \"XXLX\": \"04\",\n" +
//                "        \"SJDY\": {\n" +
//                "            \"DJZS\": 2500,\n" +
//                "            \"DJFHBFB\": 80,\n" +
//                "            \"DCDY\": 4800,\n" +
//                "            \"DCDL\": 120,\n" +
//                "            \"DCDLBFB\": 90\n" +
//                "        }\n" +
//                "    },\n" +
//                "    {\n" +
//                "        \"XXLX\": \"03\",\n" +
//                "        \"SJDY\": {\n" +
//                "            \"CS\": 120.5,\n" +
//                "            \"DQYL\": 100.2,\n" +
//                "            \"FDJNJ\": 10.5,\n" +
//                "            \"MCNJ\": 5.2,\n" +
//                "            \"FDJZS\": 2500,\n" +
//                "            \"FDJRLLL\": 1560,\n" +
//                "            \"TWCSY\": 0.8,\n" +
//                "            \"TWCXY\": 1.2,\n" +
//                "            \"JQL\": 1000,\n" +
//                "            \"FDJLQYWD\": 90,\n" +
//                "            \"TWCWD\": 300,\n" +
//                "            \"DWZT\": 1,\n" +
//                "            \"JD\": 113.55,\n" +
//                "            \"WD\": 22.65,\n" +
//                "            \"LJLC\": 250000\n" +
//                "        }\n" +
//                "    },\n" +
//                "    {\n" +
//                "        \"XXLX\": \"05\",\n" +
//                "        \"SJDY\": {\n" +
//                "            \"CS\": 120.5,\n" +
//                "            \"DQYL\": 100.2,\n" +
//                "            \"FDJNJ\": 10.5,\n" +
//                "            \"MCNJ\": 5.2,\n" +
//                "            \"FDJZS\": 2500,\n" +
//                "            \"FDJRLLL\": 1560,\n" +
//                "            \"TWCSY\": 0.8,\n" +
//                "            \"TWCXY\": 1.2,\n" +
//                "            \"TWCNOX\": 100,\n" +
//                "            \"JQL\": 1000,\n" +
//                "            \"FDJLQYWD\": 90,\n" +
//                "            \"TWCWD\": 300,\n" +
//                "            \"DWZT\": 1,\n" +
//                "            \"JD\": 113.55,\n" +
//                "            \"WD\": 22.65,\n" +
//                "            \"LJLC\": 250000\n" +
//                "        }\n" +
//                "    },\n" +
//                "    {\n" +
//                "        \"XXLX\": \"80\",\n" +
//                "        \"SJDY\": {\n" +
//                "            \"FDJNJMS\": \"9\",\n" +
//                "            \"YMTB\": 50,\n" +
//                "            \"LJYH\": 150000,\n" +
//                "            \"NSXWD\": 80,\n" +
//                "            \"SJNSPSL\": 2000,\n" +
//                "            \"LJNSXH\": 5550,\n" +
//                "            \"DPFWD\": 500\n" +
//                "        }\n" +
//                "    },\n" +
//                "    {\n" +
//                "        \"XXLX\": \"01\",\n" +
//                "        \"SJDY\": {\n" +
//                "            \"OBDZDXY\": \"0\",\n" +
//                "            \"MIL\": \"0\",\n" +
//                "            \"ZDZCZT\": \"0000000000000000\",\n" +
//                "            \"ZDJXZT\": \"0000000000000000\",\n" +
//                "            \"VIN\": \"12345678901234567\",\n" +
//                "            \"RJBDSBH\": \"222222222222222222\",\n" +
//                "            \"CVN\": \"222222222222222222\",\n" +
//                "            \"IUPR\": \"012345678901234567890123456\",\n" +
//                "            \"GZMZS\": 2,\n" +
//                "            \"GZMLB\": \"41104120\"\n" +
//                "        }\n" +
//                "    }\n" +
//                "]";
//
//        ObjectMapper objectMapper = new ObjectMapper();
//        objectMapper.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
//        Map<String, Object> myMap = objectMapper.readValue(jsonStr1, Map.class);
//        System.out.println(myMap);

        String jsonString = "{\"name\":\"John\",\"age\":30,\"address\":{\"street\":\"123 Main St\",\"city\":\"Anytown\",\"state\":\"CA\"}}";
        String jsonStr1 = "[\n" +
                "    \n" +
                "    {\n" +
                "        \"XXLX\": \"04\",\n" +
                "        \"SJDY\": {\n" +
                "            \"DJZS\": 2500,\n" +
                "            \"DJFHBFB\": 80,\n" +
                "            \"DCDY\": 4800,\n" +
                "            \"DCDL\": 120,\n" +
                "            \"DCDLBFB\": 90\n" +
                "        }\n" +
                "    },\n" +
                "    {\n" +
                "        \"XXLX\": \"03\",\n" +
                "        \"SJDY\": {\n" +
                "            \"CS\": 120.5,\n" +
                "            \"DQYL\": 100.2,\n" +
                "            \"FDJNJ\": 10.5,\n" +
                "            \"MCNJ\": 5.2,\n" +
                "            \"FDJZS\": 2500,\n" +
                "            \"FDJRLLL\": 1560,\n" +
                "            \"TWCSY\": 0.8,\n" +
                "            \"TWCXY\": 1.2,\n" +
                "            \"JQL\": 1000,\n" +
                "            \"FDJLQYWD\": 90,\n" +
                "            \"TWCWD\": 300,\n" +
                "            \"DWZT\": 1,\n" +
                "            \"JD\": 113.55,\n" +
                "            \"WD\": 22.65,\n" +
                "            \"LJLC\": 250000\n" +
                "        }\n" +
                "    },\n" +
                "    {\n" +
                "        \"XXLX\": \"05\",\n" +
                "        \"SJDY\": {\n" +
                "            \"CS\": 120.5,\n" +
                "            \"DQYL\": 100.2,\n" +
                "            \"FDJNJ\": 10.5,\n" +
                "            \"MCNJ\": 5.2,\n" +
                "            \"FDJZS\": 2500,\n" +
                "            \"FDJRLLL\": 1560,\n" +
                "            \"TWCSY\": 0.8,\n" +
                "            \"TWCXY\": 1.2,\n" +
                "            \"TWCNOX\": 100,\n" +
                "            \"JQL\": 1000,\n" +
                "            \"FDJLQYWD\": 90,\n" +
                "            \"TWCWD\": 300,\n" +
                "            \"DWZT\": 1,\n" +
                "            \"JD\": 113.55,\n" +
                "            \"WD\": 22.65,\n" +
                "            \"LJLC\": 250000\n" +
                "        }\n" +
                "    },\n" +
                "    {\n" +
                "        \"XXLX\": \"80\",\n" +
                "        \"SJDY\": {\n" +
                "            \"FDJNJMS\": \"9\",\n" +
                "            \"YMTB\": 50,\n" +
                "            \"LJYH\": 150000,\n" +
                "            \"NSXWD\": 80,\n" +
                "            \"SJNSPSL\": 2000,\n" +
                "            \"LJNSXH\": 5550,\n" +
                "            \"DPFWD\": 500\n" +
                "        }\n" +
                "    },\n" +
                "    {\n" +
                "        \"XXLX\": \"01\",\n" +
                "        \"SJDY\": {\n" +
                "            \"OBDZDXY\": \"0\",\n" +
                "            \"MIL\": \"0\",\n" +
                "            \"ZDZCZT\": \"0000000000000000\",\n" +
                "            \"ZDJXZT\": \"0000000000000000\",\n" +
                "            \"VIN\": \"12345678901234567\",\n" +
                "            \"RJBDSBH\": \"222222222222222222\",\n" +
                "            \"CVN\": \"222222222222222222\",\n" +
                "            \"IUPR\": \"012345678901234567890123456\",\n" +
                "            \"GZMZS\": 2,\n" +
                "            \"GZMLB\": \"41104120\"\n" +
                "        }\n" +
                "    }\n" +
                "]";
        ObjectMapper objectMapper1 = new ObjectMapper();
        List<HashMap<String, Object>> map = objectMapper1.readValue(jsonStr1, new TypeReference<List<HashMap<String, Object>>>() {
        });
        MonitorDetailsEntity monitorDetailsEntity = new MonitorDetailsEntity();
        for (HashMap<String, Object> stringObjectHashMap : map) {
            if (DataTypeEnum.XXLX01.getValue().equals(stringObjectHashMap.get("XXLX"))) {
                ObdInfoEntity obdInfoEntity = objectMapper1.convertValue(stringObjectHashMap.get("SJDY"), ObdInfoEntity.class);
                monitorDetailsEntity.setObdInfo(obdInfoEntity);
            }
            if (DataTypeEnum.XXLX02.getValue().equals(stringObjectHashMap.get("XXLX"))) {
                DpfAndScr dpfAndScr = objectMapper1.convertValue(stringObjectHashMap.get("SJDY"), DpfAndScr.class);
                monitorDetailsEntity.setEngineInfoType1(dpfAndScr);
            }
            if (DataTypeEnum.XXLX03.getValue().equals(stringObjectHashMap.get("XXLX")) ||
                    DataTypeEnum.XXLX05.getValue().equals(stringObjectHashMap.get("XXLX"))) {
                CatalyticConverter catalyticConverter = objectMapper1.convertValue(stringObjectHashMap.get("SJDY"), CatalyticConverter.class);
                monitorDetailsEntity.setEngineInfoType2(catalyticConverter);
            }
            if (DataTypeEnum.XXLX04.getValue().equals(stringObjectHashMap.get("XXLX"))) {
                ObdAdditionalInfo obdAdditionalInfo = objectMapper1.convertValue(stringObjectHashMap.get("SJDY"), ObdAdditionalInfo.class);
                monitorDetailsEntity.setAdditionalInfo(obdAdditionalInfo);
            }
            if (DataTypeEnum.XXLX06.getValue().equals(stringObjectHashMap.get("XXLX"))) {
            }
            if (DataTypeEnum.XXLX80.getValue().equals(stringObjectHashMap.get("XXLX"))) {
                ObdOtherInfoEntity obdOtherInfoEntity = objectMapper1.convertValue(stringObjectHashMap.get("SJDY"), ObdOtherInfoEntity.class);
                monitorDetailsEntity.setOtherInfo(obdOtherInfoEntity);
            }
        }
        System.out.println(monitorDetailsEntity);
    }
}
